package com.hankol.feature_wine_meal

import android.annotation.SuppressLint
import com.alibaba.android.arouter.facade.annotation.Route
import com.baselibrary.activity.BaseActivity
import com.baselibrary.router.ActivityRouter
import com.hankol.feature_wine_meal.api.WineMealHelp
import com.hankol.feature_wine_meal.databinding.ActivityWineMealWebBinding
import com.hankol.feature_wine_meal.viewmodel.WineMealWebViewModel
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener

@Route(path = ActivityRouter.WINE_MEAL.WINE_MEAL_INTRO)
class WineMealWebActivity : BaseActivity() {
    private val mWineMealHelp = ActivityRouter.getARouterInterface<WineMealHelp>(ActivityRouter.WINE_MEAL.WINE_MEAL_HELP)
    private lateinit var dataBinding: ActivityWineMealWebBinding
    private lateinit var mViewModel: WineMealWebViewModel
    override fun getLayoutId(): Int {
        initImmersion(true)
        return R.layout.activity_wine_meal_web
    }

    @SuppressLint("SetJavaScriptEnabled")
    override fun init() {
        dataBinding = getDataBinding<ActivityWineMealWebBinding>()
        mViewModel = getActivityViewModelProvider(this).get(WineMealWebViewModel::class.java)
        mViewModel.initWeb(dataBinding.bridgeWebSign.settings)
        initListener()
        dataBinding.bridgeWebSign.loadUrl(mWineMealHelp.getIntroduceUrl() + "?type=1")
    }

    fun initListener() {
        dataBinding.springRefresh.setOnRefreshLoadMoreListener(object : OnRefreshLoadMoreListener {
            override fun onRefresh(refreshLayout: RefreshLayout) {
                dataBinding.springRefresh.finishRefresh()
            }

            override fun onLoadMore(refreshLayout: RefreshLayout) {
                dataBinding.springRefresh.finishLoadMore()

            }

        })
        dataBinding.ivWineDetailsBack.setOnClickListener { finish() }
        dataBinding.imgWineWebShare.setOnClickListener {
            mViewModel.showShare(this, mWineMealHelp)
        }
    }
}